﻿@using zy_simu.Data;
@using Microsoft.AspNetCore.Components.Forms

<InputFile OnChange="HandleFileSelected" multiple accept=".hex,.bin" />
<Divider></Divider>
<div style="display:flex; align-items: center; margin-bottom:5px">
    <div style="width:70%; margin-right:5px"></div>
    <div style="width:15%; margin-right:5px">
        <Button Color="Color.Primary" OnClick="OnSaveClick"><i class="fas fa-floppy-disk"></i>存储</Button>
    </div>
    <div style="width:15%; margin-right:5px">
        <Button @ref="button_close" Color="Color.Primary" OnClick="OnCloseClick"><i class="fas fa-xmark"></i>关闭</Button>
    </div>
</div>

@code {
    // [Parameter]
    // public EventCallback<string> OnFileSelected { get; set; }
    [Parameter]
    public Button button_close { get; set; } = new();
    [Parameter]
    public DialogOption option { get; set; }
    [Parameter]
    public IBrowserFile SelFile { get; set; }

    public void OnCloseClick()
    {
        option.CloseDialogAsync();
    }
    private void OnSaveClick()
    {
        // string jsonString = JsonSerializer.Serialize(emu_cfg);
        // File.WriteAllText(@".\app\zq_simu.config", jsonString);
        // Microsoft.Web.WebView2.Core.CoreWebView2? view = blazor_webview.get_webview();
        // if (view != null)
        //     view.Reload();
        // option.CloseDialogAsync();
    }

    private void HandleFileSelected(InputFileChangeEventArgs e)
    {
        SelFile = e.File;
        System.Console.WriteLine($"File name: {SelFile.Name}");
    }
}